#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   ListView.py
@Time    :   2020/07/15 10:05:04
@Author  :   Xiong qiufeng
@Version :   1.0
@Contact :   1528399071@qq.com
@License :   (C)Copyright 2017-2018, Liugroup-NLPR-CASIA
@Desc    :   None
'''


from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class ListView(QListView):
    select_row = 0
    signal_clicked = pyqtSignal(int)
    def __init__(self, parent=None):
        super(QListView, self).__init__(parent)
        self.model = QStringListModel()
        self.setModel(self.model)
        self.clicked.connect(self.handleItemClicked)

    def update(self, items):
        self.model.setStringList(items)

    def addItem(self):
        pass

    def deleteRow(self):
        self.model.removeRow(self.select_row)

    def handleItemClicked(self, item):
        self.select_row = item.row()
        self.signal_clicked.emit(self.select_row)

    def setClicked(self, index):
        self.setCurrentIndex(self.model.index(index, 0))
